---
title: "RACIAL BIAS AND PUBLIC SUPPORT FOR US DRONE STRIKES = Word Clouds Replicaiton Kit"
author: "Paul Lushenko"
date: "6/26/2024"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE)
library(plyr)
library(dplyr)
library(ggplot2)
library(readr)
library(ggpubr)
library(tidyverse)
library(tidyr)
library(stargazer)
library(corrplot)
library(Hmisc)
library(margins)
library(magrittr)
library(wordcloud)
library(tm)
library(grid)
library(coefplot)
library(gplots)
library(car)
library(rstatix)
library(emmeans)
library(lmtest)
library(sandwich)
library(effects)
library(Interact)
library(sciplot)
library(lsr)
library(qwraps2)
library(gtsummary)
library(kableExtra)
library(caret)
library(ggthemes)
library(ggprism)
library(patchwork)
library(magrittr)
library(rstatix)
library(sjmisc)
library(sjPlot)
library(scales)   
```

```{r read in data, include=FALSE}
CTL <- readLines("")
T1 <- readLines("")
T2 <- readLines("")
T3 <- readLines("")
T4 <- readLines("")
T5 <- readLines("")
T6 <- readLines("")
T7 <- readLines("")
T8 <- readLines("")
T9 <- readLines("")
```

### Word Clouds:

#### a) Treatment One:

```{r T1, echo=FALSE, results='hide'}
T1 <- Corpus(VectorSource(T1))
inspect(T1)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T1 <- tm_map(T1, toSpace, "/")
T1 <- tm_map(T1, toSpace, "@")
T1 <- tm_map(T1, toSpace, "\\|")

T1  <- tm_map(T1, content_transformer(tolower))
T1  <- tm_map(T1, removeNumbers)
T1  <- tm_map(T1, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T1  <- tm_map(T1, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))   
T1 <- tm_map(T1, removePunctuation)
T1 <- tm_map(T1, stripWhitespace)

dtmT1 <- TermDocumentMatrix(T1)
m <- as.matrix(dtmT1)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### b) Treatment Two:

```{r T2, echo=FALSE, results='hide'}
T2 <- Corpus(VectorSource(T2))
inspect(T2)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T2 <- tm_map(T2, toSpace, "/")
T2 <- tm_map(T2, toSpace, "@")
T2 <- tm_map(T2, toSpace, "\\|")

T2  <- tm_map(T2, content_transformer(tolower))
T2  <- tm_map(T2, removeNumbers)
T2  <- tm_map(T2, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T2  <- tm_map(T2, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))  
T2 <- tm_map(T2, removePunctuation)
T2 <- tm_map(T2, stripWhitespace)

dtmT2 <- TermDocumentMatrix(T2)
m <- as.matrix(dtmT2)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### c) Treatment Three:

```{r T3, echo=FALSE, results='hide'}
T3 <- Corpus(VectorSource(T3))
inspect(T3)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T3 <- tm_map(T3, toSpace, "/")
T3 <- tm_map(T3, toSpace, "@")
T3 <- tm_map(T3, toSpace, "\\|")

T3  <- tm_map(T3, content_transformer(tolower))
T3  <- tm_map(T3, removeNumbers)
T3  <- tm_map(T3, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T3  <- tm_map(T3, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))   
T3 <- tm_map(T3, removePunctuation)
T3 <- tm_map(T3, stripWhitespace)

dtmT3 <- TermDocumentMatrix(T3)
m <- as.matrix(dtmT3)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### d) Treatment Four:

```{r T4, echo=FALSE, results='hide'}
T4 <- Corpus(VectorSource(T4))
inspect(T4)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T4 <- tm_map(T4, toSpace, "/")
T4 <- tm_map(T4, toSpace, "@")
T4 <- tm_map(T4, toSpace, "\\|")

T4  <- tm_map(T4, content_transformer(tolower))
T4  <- tm_map(T4, removeNumbers)
T4  <- tm_map(T4, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T4  <- tm_map(T4, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))   
T4 <- tm_map(T4, removePunctuation)
T4 <- tm_map(T4, stripWhitespace)

dtmT4 <- TermDocumentMatrix(T4)
m <- as.matrix(dtmT4)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### e) Treatment Five:

```{r T5, echo=FALSE, results='hide'}
T5 <- Corpus(VectorSource(T5))
inspect(T5)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T5 <- tm_map(T5, toSpace, "/")
T5 <- tm_map(T5, toSpace, "@")
T5 <- tm_map(T5, toSpace, "\\|")

T5  <- tm_map(T5, content_transformer(tolower))
T5  <- tm_map(T5, removeNumbers)
T5  <- tm_map(T5, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T5  <- tm_map(T5, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))    
T5 <- tm_map(T5, removePunctuation)
T5 <- tm_map(T5, stripWhitespace)

dtmT5 <- TermDocumentMatrix(T5)
m <- as.matrix(dtmT5)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### f) Treatment Six:

```{r T6, echo=FALSE, results='hide'}
T6 <- Corpus(VectorSource(T6))
inspect(T6)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T6 <- tm_map(T6, toSpace, "/")
T6 <- tm_map(T6, toSpace, "@")
T6 <- tm_map(T6, toSpace, "\\|")

T6  <- tm_map(T6, content_transformer(tolower))
T6  <- tm_map(T6, removeNumbers)
T6  <- tm_map(T6, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T6  <- tm_map(T6, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))    
T6 <- tm_map(T6, removePunctuation)
T6 <- tm_map(T6, stripWhitespace)

dtmT6 <- TermDocumentMatrix(T6)
m <- as.matrix(dtmT6)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### g) Treatment Seven:

```{r T7, echo=FALSE, results='hide'}
T7 <- Corpus(VectorSource(T7))
inspect(T7)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T7 <- tm_map(T7, toSpace, "/")
T7 <- tm_map(T7, toSpace, "@")
T7 <- tm_map(T7, toSpace, "\\|")

T7  <- tm_map(T7, content_transformer(tolower))
T7  <- tm_map(T7, removeNumbers)
T7  <- tm_map(T7, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T7  <- tm_map(T7, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))  
T7 <- tm_map(T7, removePunctuation)
T7 <- tm_map(T7, stripWhitespace)

dtmT7 <- TermDocumentMatrix(T7)
m <- as.matrix(dtmT7)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### h) Treatment Eight:

```{r T8, echo=FALSE, results='hide'}
T8 <- Corpus(VectorSource(T8))
inspect(T8)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T8 <- tm_map(T8, toSpace, "/")
T8 <- tm_map(T8, toSpace, "@")
T8 <- tm_map(T8, toSpace, "\\|")

T8  <- tm_map(T8, content_transformer(tolower))
T8  <- tm_map(T8, removeNumbers)
T8  <- tm_map(T8, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T8  <- tm_map(T8, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))  
T8 <- tm_map(T8, removePunctuation)
T8 <- tm_map(T8, stripWhitespace)

dtmT8 <- TermDocumentMatrix(T8)
m <- as.matrix(dtmT8)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```

#### i) Treatment Nine:

```{r T9, echo=FALSE, results='hide'}
T9 <- Corpus(VectorSource(T9))
inspect(T9)

toSpace <- content_transformer(function (x , pattern) gsub(pattern, " ", x))
T9 <- tm_map(T9, toSpace, "/")
T9 <- tm_map(T9, toSpace, "@")
T9 <- tm_map(T9, toSpace, "\\|")

T9  <- tm_map(T9, content_transformer(tolower))
T9  <- tm_map(T9, removeNumbers)
T9  <- tm_map(T9, removeWords, stopwords("english"))
# Remove your own stop word
# specify your stopwords as a character vector
T9  <- tm_map(T9, removeWords, c("strike", "strikes","terrorist","terrorists","considered","likes","can","feel","made","list",
                                  "listlanguage","like","person","one","think","get","also","cause","idea","drone","support",
                                 "good","people"))  
T9 <- tm_map(T9, removePunctuation)
T9 <- tm_map(T9, stripWhitespace)

dtmT9 <- TermDocumentMatrix(T9)
m <- as.matrix(dtmT9)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v),freq=v)
head(d, 50)

set.seed(14853)
wordcloud(words = d$word, freq = d$freq, min.freq = 3,
          max.words=200, random.order=FALSE, rot.per=0.35, 
          colors=brewer.pal(8, "Dark2"))
```